import { action, observable } from 'mobx-miniprogram'

export const store = observable({

    //后端服务地址
    programURL: 'http://localhost:8880',

    //tabBar状态
    activeTabBarIndex: 1,
    updateActiveTabBarIndex: action(function(index) {
        this.activeTabBarIndex = index
    }),

    //登录凭证token
    token: null,
    updateToken: action(function(token) {
        this.token = token
    }),

    //当前用户数据
    userInfo: {},
    updateUserInfo: action(function(user) {
        this.userInfo = user
    }),
    updateUserName: action(function(name) {
        this.userInfo.nickname = name
    }),
    updateUserAvatar: action(function(url) {
        this.userInfo.avatarUrl = url
    }),


    // 状态
    imagePath: '',
    detectionResult: null,
    isLoading: false,
    // 动作
    setImagePath: action(function(path) {
        this.imagePath = path
    }),
    setDetectionResult: action(function(result) {
        this.detectionResult = result
     }),
    setIsLoading: action(function(loading) {
        this.isLoading = loading
    }),
    // 计算属性
    get hasResult() {
        return this.detectionResult !== null
    }
    
})